<template>
  <div>
    <div>
      <div>
        以公司为中心
        <el-input
          class="inputWidth"
          v-model="meter"
          @blur="switchover"
        ></el-input>
        米,
        <span class="spanMargin">为圈内</span>
      </div>
      <div class="divMargin">
        <span class="spanMarin">提成分类</span>
        <el-radio-group v-model="radio" @input="switchover">
          <el-radio label="1">分类提成</el-radio>
          <el-radio label="2">商品提成</el-radio>
        </el-radio-group>
      </div>
      <div>
        押金退款单桶
        <el-input
          class="inputWidth"
          v-model="refund"
          @blur="switchover"
        ></el-input>
        元
      </div>
      <div>
        <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
          <el-tab-pane label="分类提成" name="first">
            <el-form
              ref="form"
              :model="classify1"
              label-width="80px"
              class="formMargin"
            >
              <div class="formMargin">
                <el-form-item label="分类">
                  <el-input
                    v-model="classify1.bottledName"
                    class="inputMig"
                    :disabled="true"
                  ></el-input>
                </el-form-item>
                <div class="diFlex">
                  <el-form-item label="提成类型">
                    <el-input
                      v-model="classify1.inside"
                      class="inputMig"
                      :disabled="true"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="提成方式">
                    <el-select
                      v-model="classify1.Inside_is_type"
                      placeholder="请选择提成方式"
                    >
                      <el-option label="金额" :value="2"></el-option>
                      <el-option label="百分比" :value="1"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="请输入">
                    <el-input
                      v-if="this.classify1.Inside_is_type == 1"
                      v-model="classify1.Inside_pfb"
                      placeholder="请输入提成百分比"
                    ></el-input>
                    <el-input
                      v-else
                      v-model="classify1.Inside_price"
                      placeholder="请输入提成金额"
                    ></el-input>
                  </el-form-item>
                </div>
                <div class="diFlex">
                  <el-form-item label="提成类型">
                    <el-input
                      v-model="classify1.external"
                      class="inputMig"
                      :disabled="true"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="提成方式">
                    <el-select
                      v-model="classify1.outside_is_type"
                      placeholder="请选择提成方式"
                    >
                      <el-option label="金额" :value="2"></el-option>
                      <el-option label="百分比" :value="1"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="请输入">
                    <el-input
                      v-if="this.classify1.outside_is_type == 1"
                      v-model="classify1.outside_bfb"
                      placeholder="请输入提成百分比"
                    ></el-input>
                    <el-input
                      v-else
                      v-model="classify1.outside_price"
                      placeholder="请输入提成金额"
                    ></el-input>
                  </el-form-item>
                </div>
              </div>
            </el-form>
            <el-form
              ref="form"
              :model="classify2"
              label-width="80px"
              class="formMargin"
            >
              <div class="formMargin">
                <el-form-item label="分类">
                  <el-input
                    v-model="classify2.bottledName"
                    class="inputMig"
                    :disabled="true"
                  ></el-input>
                </el-form-item>
                <div class="diFlex">
                  <el-form-item label="提成类型">
                    <el-input
                      v-model="classify2.inside"
                      class="inputMig"
                      :disabled="true"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="提成方式">
                    <el-select
                      v-model="classify2.Inside_is_type"
                      placeholder="请选择提成方式"
                    >
                      <el-option label="金额" :value="2"></el-option>
                      <el-option label="百分比" :value="1"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="请输入">
                    <el-input
                      v-if="this.classify2.Inside_is_type == 1"
                      v-model="classify2.Inside_pfb"
                      placeholder="请输入提成百分比"
                    ></el-input>
                    <el-input
                      v-else
                      v-model="classify2.Inside_price"
                      placeholder="请输入提成金额"
                    ></el-input>
                  </el-form-item>
                </div>
                <div class="diFlex">
                  <el-form-item label="提成类型">
                    <el-input
                      v-model="classify2.external"
                      class="inputMig"
                      :disabled="true"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="提成方式">
                    <el-select
                      v-model="classify2.outside_is_type"
                      placeholder="请选择提成方式"
                    >
                      <el-option label="金额" :value="2"></el-option>
                      <el-option label="百分比" :value="1"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="请输入">
                    <el-input
                      v-if="this.classify2.outside_is_type == 1"
                      v-model="classify2.outside_bfb"
                      placeholder="请输入提成百分比"
                    ></el-input>
                    <el-input
                      v-else
                      v-model="classify2.outside_price"
                      placeholder="请输入提成金额"
                    ></el-input>
                  </el-form-item>
                </div>
              </div>
            </el-form>
            <el-form
              ref="form"
              :model="classify3"
              label-width="80px"
              class="formMargin"
            >
              <div class="formMargin">
                <el-form-item label="分类">
                  <el-input
                    v-model="classify3.bottledName"
                    class="inputMig"
                    :disabled="true"
                  ></el-input>
                </el-form-item>
                <div class="diFlex">
                  <el-form-item label="提成类型">
                    <el-input
                      v-model="classify3.inside"
                      class="inputMig"
                      :disabled="true"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="提成方式">
                    <el-select
                      v-model="classify3.Inside_is_type"
                      placeholder="请选择提成方式"
                    >
                      <el-option label="金额" :value="2"></el-option>
                      <el-option label="百分比" :value="1"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="请输入">
                    <el-input
                      v-if="this.classify3.Inside_is_type == 1"
                      v-model="classify3.Inside_pfb"
                      placeholder="请输入提成百分比"
                    ></el-input>
                    <el-input
                      v-else
                      v-model="classify3.Inside_price"
                      placeholder="请输入提成金额"
                    ></el-input>
                  </el-form-item>
                </div>
                <div class="diFlex">
                  <el-form-item label="提成类型">
                    <el-input
                      v-model="classify3.external"
                      class="inputMig"
                      :disabled="true"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="提成方式">
                    <el-select
                      v-model="classify3.outside_is_type"
                      placeholder="请选择提成方式"
                    >
                      <el-option label="金额" :value="2"></el-option>
                      <el-option label="百分比" :value="1"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="请输入">
                    <el-input
                      v-if="this.classify3.outside_is_type == 1"
                      v-model="classify3.outside_bfb"
                      placeholder="请输入提成百分比"
                    ></el-input>
                    <el-input
                      v-else
                      v-model="classify3.outside_price"
                      placeholder="请输入提成金额"
                    ></el-input>
                  </el-form-item>
                </div>
              </div>
            </el-form>
            <el-form
              ref="form"
              :model="classify4"
              label-width="80px"
              class="formMargin"
            >
              <div class="formMargin">
                <el-form-item label="分类">
                  <el-input
                    v-model="classify4.bottledName"
                    class="inputMig"
                    :disabled="true"
                  ></el-input>
                </el-form-item>
                <div class="diFlex">
                  <el-form-item label="提成类型">
                    <el-input
                      v-model="classify4.inside"
                      class="inputMig"
                      :disabled="true"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="提成方式">
                    <el-select
                      v-model="classify4.Inside_is_type"
                      placeholder="请选择提成方式"
                    >
                      <el-option label="金额" :value="2"></el-option>
                      <el-option label="百分比" :value="1"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="请输入">
                    <el-input
                      v-if="this.classify4.Inside_is_type == 1"
                      v-model="classify4.Inside_pfb"
                      placeholder="请输入提成百分比"
                    ></el-input>
                    <el-input
                      v-else
                      v-model="classify4.Inside_price"
                      placeholder="请输入提成金额"
                    ></el-input>
                  </el-form-item>
                </div>
                <div class="diFlex">
                  <el-form-item label="提成类型">
                    <el-input
                      v-model="classify4.external"
                      class="inputMig"
                      :disabled="true"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="提成方式">
                    <el-select
                      v-model="classify4.outside_is_type"
                      placeholder="请选择提成方式"
                    >
                      <el-option label="金额" :value="2"></el-option>
                      <el-option label="百分比" :value="1"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="请输入">
                    <el-input
                      v-if="this.classify4.outside_is_type == 1"
                      v-model="classify4.outside_bfb"
                      placeholder="请输入提成百分比"
                    ></el-input>
                    <el-input
                      v-else
                      v-model="classify4.outside_price"
                      placeholder="请输入提成金额"
                    ></el-input>
                  </el-form-item>
                </div>
              </div>
            </el-form>
            <div class="divAuto">
              <!-- <el-button @click="cancel">取消</el-button> -->
              <el-button type="primary" class="groupMargin" @click="keepForm"
                >保存</el-button
              >
            </div>
          </el-tab-pane>
          <el-tab-pane label="商品提成" name="second">
            <div class="diFlex">
              <el-button type="primary" @click="butWater">全部</el-button>
              <el-button
                type="primary"
                v-for="(item, index) in catData"
                :key="index"
                @click="caskWater(item)"
                >{{ item.name }}
              </el-button>
            </div>
            <div>
              <el-table
                v-loading="loading"
                :data="tableData"
                border
                style="width: 100%; margin-top: 20px"
                max-height="600"
              >
                <el-table-column align="center" label="ID" prop="id" width="70">
                </el-table-column>
                <el-table-column prop="name" align="center" label="商品名称">
                </el-table-column>
                <el-table-column prop="price" align="center" label="商品价格">
                </el-table-column>
                <el-table-column prop="inside" align="center" label="范围内">
                </el-table-column>
                <el-table-column
                  prop="Inside_is_type_text"
                  align="center"
                  label="提成方式"
                >
                </el-table-column>
                <el-table-column
                  prop="Inside_price_text"
                  align="center"
                  label="数值"
                >
                </el-table-column>
                <el-table-column prop="external" align="center" label="范围外">
                </el-table-column>
                <el-table-column
                  prop="outside_is_type_text"
                  align="center"
                  label="提成方式"
                >
                </el-table-column>
                <el-table-column
                  prop="outside_price_text"
                  align="center"
                  label="数值"
                >
                </el-table-column>
                <el-table-column align="center" label="操作">
                  <template slot-scope="scope">
                    <el-button
                      type="primary"
                      size="mini"
                      @click="compile(scope.row)"
                      >编辑</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="page"
                :page-sizes="[10, 200, 300, 400]"
                :page-size="100"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
              >
              </el-pagination>
            </div>
            <el-dialog
              :visible.sync="dialogVisible"
              width="50%"
              :before-close="padlock"
            >
              <span>
                <el-form
                  ref="form"
                  :model="commodity"
                  label-width="80px"
                  class="formMargin"
                >
                  <div class="diFlex">
                    <el-form-item label="商品名称">
                      <el-input
                        v-model="commodity.name"
                        class="inputMig"
                        :disabled="true"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="商品价格">
                      <el-input
                        v-model="commodity.price"
                        class="inputWite"
                        :disabled="true"
                      ></el-input>
                    </el-form-item>
                  </div>
                  <div class="diFlex">
                    <el-form-item label="提成类型">
                      <el-input
                        v-model="commodity.inside"
                        class="inputMig"
                        :disabled="true"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="提成方式">
                      <el-select
                        v-model="commodity.Inside_is_type"
                        placeholder="请选择提成方式"
                      >
                        <el-option label="金额" :value="2"></el-option>
                        <el-option label="百分比" :value="1"></el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="请输入">
                      <el-input
                        v-if="this.commodity.Inside_is_type == 1"
                        v-model="commodity.Inside_pfb"
                        placeholder="请输入提成百分比"
                      ></el-input>
                      <el-input
                        v-else
                        v-model="commodity.Inside_price"
                        placeholder="请输入提成金额"
                      ></el-input>
                    </el-form-item>
                  </div>
                  <div class="diFlex">
                    <el-form-item label="提成类型">
                      <el-input
                        v-model="commodity.external"
                        class="inputMig"
                        :disabled="true"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="提成方式">
                      <el-select
                        v-model="commodity.outside_is_type"
                        placeholder="请选择提成方式"
                      >
                        <el-option label="金额" :value="2"></el-option>
                        <el-option label="百分比" :value="1"></el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="请输入">
                      <el-input
                        v-if="this.commodity.outside_is_type == 1"
                        v-model="commodity.outside_bfb"
                        placeholder="请输入提成百分比"
                      ></el-input>
                      <el-input
                        v-else
                        v-model="commodity.outside_price"
                        placeholder="请输入提成金额"
                      ></el-input>
                    </el-form-item>
                  </div>
                  <div class="divAuto">
                    <el-button @click="commodityCancel">取消</el-button>
                    <el-button
                      type="primary"
                      class="groupMargin"
                      @click="commodityForm"
                      >保存</el-button
                    >
                  </div>
                </el-form>
              </span>
            </el-dialog>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>

<script>
import "default-passive-events";
import {
  Performance,
  addManCe,
  catDinJi,
  upWokPer,
  wokPer,
  commission,
  products,
} from "../../../../utils/api.js";

export default {
  data() {
    return {
      token: sessionStorage.getItem("token"),
      loading: false,
      //弹框
      dialogVisible: false,
      meter: "",
      radio: "",
      refund: "",
      type: "0",
      //标签页
      activeName: "first",
      //分类
      classifyS: [],
      classify1: {
        bottledName: "桶装水",
        external: "圈外",
        inside: "圈内",
        Inside_is_type: "",
        Inside_pfb: "",
        Inside_price: "",
        outside_is_type: "",
        outside_bfb: "",
        outside_price: "",
      },
      classify2: {
        bottledName: "定制LOGO水",
        external: "圈外",
        inside: "圈内",
        Inside_is_type: "",
        Inside_pfb: "",
        Inside_price: "",
        outside_is_type: "",
        outside_bfb: "",
        outside_price: "",
      },
      classify3: {
        bottledName: "瓶装水",
        external: "圈外",
        inside: "圈内",
        Inside_is_type: "",
        Inside_pfb: "",
        Inside_price: "",
        outside_is_type: "",
        outside_bfb: "",
        outside_price: "",
      },
      classify4: {
        bottledName: "一次性水",
        external: "圈外",
        inside: "圈内",
        Inside_is_type: "",
        Inside_pfb: "",
        Inside_price: "",
        outside_is_type: "",
        outside_bfb: "",
        outside_price: "",
      },
      catData: [],
      //商品
      commodity: {
        name: "",
        external: "圈外",
        inside: "圈内",
        Inside_is_type: "",
        Inside_price: "",
        Inside_pfb: "",
        outside_is_type: "",
        outside_bfb: "",
        outside_price: "",
        price: "",
        goods_id: "",
        id: "",
      },
      tableData: [],
      //分页
      limit: 10,
      page: 1,
      total: 0,
      // rules: {
      //   name: [
      //     {
      //       required: true,
      //       message: "请输入提成金额/百分比",
      //       trigger: "change",
      //     },
      //     {
      //       validator: (rule, value, callback) => {
      //         var reg = /^[0-9]+.?[0-9]*$/;
      //         if (!reg.test(value)) {
      //           callback(new Error("请输入数字"));
      //         } else {
      //           callback();
      //         }
      //       },
      //       trigger: "blur",
      //     },
      //   ],
      // },
    };
  },
  methods: {
    empty() {
      this.commodity.Inside_is_type = "";
      this.commodity.Inside_price = "";
      this.commodity.Inside_pfb = "";
      this.commodity.outside_is_type = "";
      this.commodity.outside_bfb = "";
      this.commodity.outside_price = "";
      this.commodity.price = "";
      this.commodity.goods_id = "";
      this.commodity.id = "";
      this.commodity.name = "";
    },
    //保存
    keepForm() {
      let obj = JSON.parse(JSON.stringify(this.classify1));
      delete obj.bottledName;
      delete obj.external;
      delete obj.inside;
      let obj1 = JSON.parse(JSON.stringify(this.classify2));
      delete obj1.bottledName;
      delete obj1.external;
      delete obj1.inside;
      let obj2 = JSON.parse(JSON.stringify(this.classify3));
      delete obj2.bottledName;
      delete obj2.external;
      delete obj2.inside;
      let obj3 = JSON.parse(JSON.stringify(this.classify4));
      delete obj3.bottledName;
      delete obj3.external;
      delete obj3.inside;
      this.classifyS.push(obj, obj1, obj2, obj3);

      this.classifyS.forEach((item) => {
        item.Inside_pfb = Number(item.Inside_pfb);
        item.Inside_price = Number(item.Inside_price);
        item.outside_bfb = Number(item.outside_bfb);
        item.outside_price = Number(item.outside_price);
      });
      this.addManCes(this.meter, this.radio, this.classifyS);
    },
    //取消
    cancel() {
      this.Performances();
    },
    //标签页
    handleClick(tab) {
      if (tab.index == 0) {
        this.Performances();
        this.upWokPes();
      }
      if (tab.index == 1) {
        this.catDinJis();
        this.commissions();
      }
    },
    //序号
    indexMethod(index) {
      if (this.token < this.limit) {
        return this.total - index;
      } else {
        return this.total - (this.page - 1) * this.limit - index;
      }
    },
    //编辑
    compile(row) {
      let obj = JSON.parse(JSON.stringify(row));
      this.commodity.Inside_is_type = obj.Inside_is_type;
      this.commodity.Inside_price = obj.Inside_price;
      this.commodity.Inside_pfb = obj.Inside_pfb;
      this.commodity.outside_is_type = obj.outside_is_type;
      this.commodity.outside_bfb = obj.outside_bfb;
      this.commodity.outside_price = obj.outside_price;
      this.commodity.price = obj.price;
      this.commodity.goods_id = obj.goods_id;
      this.commodity.id = obj.id;
      this.commodity.name = obj.name;
      this.dialogVisible = true;
    },
    //关闭
    padlock(done) {
      this.empty();
      done();
    },
    //商品保存
    commodityForm() {
      let obj = JSON.parse(JSON.stringify(this.commodity));
      delete obj.external;
      delete obj.inside;
      delete obj.name;
      delete obj.price;
      if (obj.id == null) {
        obj.id = 0;
      }
      obj.Inside_pfb = Number(obj.Inside_pfb);
      obj.Inside_price = Number(obj.Inside_price);
      obj.outside_price = Number(obj.outside_price);
      obj.outside_bfb = Number(obj.outside_bfb);
      // console.log(typeof obj.Inside_pfb)
      let inner = "";
      let out = "";
      let inner2 = "";
      let out2 = "";
      if (this.commodity.outside_is_type == 1) {
        //百分比
        // out = obj.outside_bfb;
        out2 = obj.outside_bfb;
      } else if (this.commodity.outside_is_type == 2) {
        //金额
        out = obj.outside_price;
      }
      if (this.commodity.Inside_is_type == 1) {
        // inner = obj.Inside_pfb;
        inner2 = obj.Inside_pfb;
      } else if (this.commodity.Inside_is_type == 2) {
        inner = obj.Inside_price;
      }
      // 小数位最多到两位的正数
      // let reg2 = /^\d+(\.\d{1,2})?$/;
      // if (!reg2.test(out) || !reg2.test(inner)) {
      //   this.$message({
      //     message: "金额请输入小数位为两位的正数",
      //     type: "error",
      //   });
      //   return;
      // }
      // if (out < 0 || out > 100) {
      //   this.$message({
      //     message: "金额请输入0-100之间的数字",
      //     type: "error",
      //   });
      //   return;
      // }
      // if (inner < 0 || inner > 100) {
      //   this.$message({
      //     message: "金额请输入0-100之间的数字",
      //     type: "error",
      //   });
      //   return;
      // }
      let sumreg = /^(100|\d{1,2}(?:\.\d{1,2})?)$/;
      if (out !== "") {
        if (!sumreg.test(out)) {
          this.$message({
            message: "金额请输入0-100之间且小数位最多为两位的数字",
            type: "error",
          });
          return;
        }
      }
      if (inner !== "") {
        if (!sumreg.test(inner)) {
          this.$message({
            message: "金额请输入0-100之间且小数位最多为两位的数字",
            type: "error",
          });
          return;
        }
      }

      // 商品提成编辑时，百分比只能填正整数
      const regex = /^(100|[1-9]\d?|0)$/;
      if (out2 != "") {
        if (!regex.test(out2)) {
          this.$message({
            message: "百分比请输入0-100的正整数",
            type: "error",
          });
          console.log(444);
          return;
        }
      }
      if (inner2 != "") {
        if (!regex.test(inner2)) {
          this.$message({
            message: "百分比请输入0-100的正整数",
            type: "error",
          });
          console.log(555);
          return;
        }
      }
      this.productSs(obj.id, obj);

      //  ！  isNan(123)  false
      // if (!isNaN(out) && !isNaN(inner)) {
      //   this.productSs(obj.id, obj);
      // } else {
      //   this.$message({
      //     message: "警告哦, 不能输入英文",
      //     type: "warning",
      //   });
      //   return;
      // }
    },
    //商品取消
    commodityCancel() {
      this.dialogVisible = false;
      this.empty();
    },
    //顶级分类
    caskWater(row) {
      let obj = JSON.parse(JSON.stringify(row));
      this.type = obj.id;
      this.commissions();
    },
    butWater() {
      this.type = 0;
      this.commissions();
    },
    //分页条数
    handleSizeChange(val) {
      this.limit = val;
      this.commissions();
    },
    //分页页数
    handleCurrentChange(val) {
      this.page = val;
      this.commissions();
    },

    //分类列表
    Performances() {
      this.loading = true;
      Performance(this.token)
        .then((res) => {
          if (res.data.status) {
            this.classify1 = res.data.data.list[0];
            if (this.classify1.goods_cat_id == 1) {
              this.classify1.bottledName = "桶装水";
              this.classify1.inside = "圈内";
              this.classify1.external = "圈外";
            }
            this.classify2 = res.data.data.list[1];
            if (this.classify2.goods_cat_id == 65) {
              this.classify2.bottledName = "一次性包装水";
              this.classify2.inside = "圈内";
              this.classify2.external = "圈外";
            }
            this.classify3 = res.data.data.list[2];
            if (this.classify3.goods_cat_id == 73) {
              this.classify3.bottledName = "瓶装水";
              this.classify3.inside = "圈内";
              this.classify3.external = "圈外";
            }
            this.classify4 = res.data.data.list[3];
            if (this.classify4.goods_cat_id == 80) {
              this.classify4.bottledName = "LOGO定制水";
              this.classify4.inside = "圈内";
              this.classify4.external = "圈外";
            }
            let timer = setTimeout(() => {
              this.loading = false;
              clearTimeout(timer);
            }, 400);
          } else {
            if (res.data.msg == "token失效,请重新进行登录") {
              this.$router.push("/login");
            }
            if (res.data.msg == "此账号没有权限") {
              this.$message.error(res.data.msg);
              this.loading = false;
            }
            let timer = setTimeout(() => {
              this.$message.error(res.data.msg);
            }, 1000);
          }
        })
        .catch((err) => {
          console.log(err.message);
        });
    },
    //保存分类
    addManCes(tbj_circle, tbj_ct_type, workers) {
      console.log("workers", workers);
      // 判断金额，不能为负数
      let regs1 = /^\d+(\.\d{1,2})?$/;
      let regs2 = /^\d+(\.\d{1,2})?$/;
      // 判断百分比，0-100之间（包含0和100），且小数位不能超过两位
      let regex = /^(100|[1-9]\d?|0)$/;
      // let regs2 = /^(?:100(\.0{1,2})?|(0?[1-9]\d?|100)(?:\.\d{1,2})?)$/;
      // 圈内百分比为0-100的整数，包含0和100
      let flag1 = workers.findIndex((e) => {
        // console.log("e", e);
        // if (regex.test(e.Inside_pfb)) {
        //   console.log("flag1", e.Inside_pfb);
        //   return regex.test(e.Inside_pfb);
        // } else {
        //   return -1;
        // }
        return !regex.test(e.Inside_pfb);
      });
      // 圈内金额为数字（不为负数）
      let flag2 = workers.findIndex((e) => {
        if (e.Inside_price >= 0 && e.Inside_price <= 100) {
          // console.log("flag2", e.Inside_price);
          return !regs1.test(e.Inside_price);
        } else {
          return -1;
        }
      });
      // 圈外百分比为0-100的整数，包含0和100
      let flag3 = workers.findIndex((e) => {
        // if (regex.test(e.outside_bfb)) {
        //   // console.log("flag3", e.outside_bfb);
        //   return -1;
        // } else {
        //   // console.log("flag33", e.outside_bfb);
        //   return 0;
        // }
        return !regex.test(e.outside_bfb);
      });
      // 圈外金额为数字（不为负数）
      let flag4 = workers.findIndex((e) => {
        if (e.outside_price >= 0 && e.outside_price <= 100) {
          // console.log("flag4", e.outside_price);
          return !regs1.test(e.outside_price);
        } else {
          return -1;
        }
      });
      let reg2 = /^(?!0+(?:\.0+)?$)(\d+(\.\d{1,2})?)$/;
      if (!reg2.test(tbj_circle)) {
        this.$message({
          message: "以公司为中心请输入大于0的数字",
          type: "error",
        });
        return;
      }
      console.log(flag1, flag2, flag3, flag4);
      if (flag1 >= 0) {
        this.$message({
          message: "圈内百分比为0-100的整数",
          type: "warning",
        });
        this.classifyS = [];
        return;
      } else if (flag2 >= 0) {
        this.$message({
          message: "圈内金额为数字（0-100）",
          type: "warning",
        });
        this.classifyS = [];
        return;
      } else if (flag3 >= 0) {
        this.$message({
          message: "圈外百分比为0-100的整数",
          type: "warning",
        });
        this.classifyS = [];
        return;
      } else if (flag4 >= 0) {
        this.$message({
          message: "圈外金额为数字（0-100）",
          type: "warning",
        });
        this.classifyS = [];
        return;
      } else {
        addManCe(
          this.token,
          tbj_circle,
          tbj_ct_type,
          JSON.stringify(workers)
        ).then((res) => {
          if (res.data.status) {
            this.$message({
              message: "保存成功",
              type: "success",
            });
            this.Performances();
            this.classifyS = [];
          } else {
            if (res.data.msg == "token失效,请重新进行登录") {
              this.$router.push("/login");
              let timer = setTimeout(() => {
                this.$message.error("错误，请刷新");
              }, 5000);
            }
            this.$message.error(res.data.msg);
            this.classifyS = [];
          }
        });
      }
    },
    //顶级分类
    catDinJis() {
      this.loading = true;
      catDinJi(this.token)
        .then((res) => {
          if (res.data.status) {
            this.catData = res.data.data;
            let timer = setTimeout(() => {
              this.loading = false;
              clearTimeout(timer);
            }, 400);
          } else {
            if (res.data.msg == "token失效,请重新进行登录") {
              this.$router.push("/login");
            }
            if (res.data.msg == "此账号没有权限") {
              this.$message.error(res.data.msg);
              this.loading = false;
            }
            let timer = setTimeout(() => {
              this.$message.error(res.data.msg);
            }, 1000);
          }
        })
        .catch((err) => {
          console.log(err.message);
        });
    },
    //提成分类
    upWokPes() {
      this.loading = true;
      upWokPer(this.token)
        .then((res) => {
          if (res.data.status) {
            this.meter = res.data.data.tbj_circle.value;
            this.radio = res.data.data.tbj_ct_type.value;
            this.refund = res.data.data.tbj_kt_price.value;
            let timer = setTimeout(() => {
              this.loading = false;
              clearTimeout(timer);
            }, 400);
          } else {
            if (res.data.msg == "token失效,请重新进行登录") {
              this.$router.push("/login");
            }
            if (res.data.msg == "此账号没有权限") {
              this.$message.error(res.data.msg);
              this.loading = false;
            }
            let timer = setTimeout(() => {
              this.$message.error(res.data.msg);
            }, 1000);
          }
        })
        .catch((err) => {
          console.log(err.message);
        });
    },
    //编辑分类类型
    wokPerS(tbj_circle, tbj_ct_type, tbj_kt_price) {
      let reg2 = /^(?!0+(?:\.0+)?$)(\d+(\.\d{1,2})?)$/;
      let reg3 = /^\d+(\.\d{1,2})?$/;
      if (!reg2.test(tbj_circle)) {
        this.$message({
          message: "以公司为中心请输入大于0的数字",
          type: "error",
        });
        return;
      }
      if (!reg3.test(tbj_kt_price) || tbj_kt_price > 100) {
        this.$message({
          message: "押金提款单桶请输入0-100之间最多两位小数的数字",
          type: "error",
        });
        return;
      }
      wokPer(this.token, tbj_circle, tbj_ct_type, tbj_kt_price).then((res) => {
        if (res.data.status) {
          this.$message({
            message: "修改成功",
            type: "success",
            onClose: (res) => {},
          });
          this.Performances();
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    //切换分类类型及米数
    switchover() {
      console.log(this.radio, this.activeName);
      this.wokPerS(this.meter, this.radio, this.refund);
    },

    //商品列表
    commissions() {
      this.loading = true;
      let type = 1;
      commission(this.token, this.page, this.limit, type, this.type)
        .then((res) => {
          if (res.data.status) {
            this.tableData = res.data.data.data;
            this.tableData.forEach((item) => {
              item.inside = "圈内";
              item.external = "圈外";
              if (item.Inside_is_type == 1) {
                item.Inside_is_type_text = "百分比";
                item.Inside_price_text = item.Inside_pfb;
              }
              if (item.Inside_is_type == 2) {
                item.Inside_is_type_text = "金额";
                item.Inside_price_text = item.Inside_price;
              }
              if (item.outside_is_type == 1) {
                item.outside_is_type_text = "百分比";
                item.outside_price_text = item.outside_bfb;
              }
              if (item.outside_is_type == 2) {
                item.outside_is_type_text = "金额";
                item.outside_price_text = item.outside_price;
              }
            });
            this.total = res.data.data.count;
            let timer = setTimeout(() => {
              this.loading = false;
              clearTimeout(timer);
            }, 400);
          } else {
            if (res.data.msg == "token失效,请重新进行登录") {
              this.$router.push("/login");
            }
            if (res.data.msg == "此账号没有权限") {
              this.$message.error(res.data.msg);
              this.loading = false;
            }
            let timer = setTimeout(() => {
              this.$message.error(res.data.msg);
            }, 1000);
          }
        })
        .catch((err) => {
          console.log(err.message);
        });
    },
    //添加商品
    productSs(id, data) {
      products(this.token, id, JSON.stringify(data)).then((res) => {
        if (res.data.status) {
          this.$message({
            message: "保存成功",
            type: "success",
          });
          this.commissions();
          this.dialogVisible = false;
          this.empty();
        } else {
          if (res.data.msg == "token失效,请重新进行登录") {
            this.$router.push("/login");
            let timer = setTimeout(() => {
              this.$message.error("错误，请刷新");
            }, 5000);
          }
          this.$message.error(res.data.msg);
          this.Performances();
        }
      });
    },
  },

  mounted() {
    this.Performances();
    this.upWokPes();
  },
  watch: {
    radio(n, o) {
      // if (tab.index == 0) {

      // }
      // if (tab.index == 1) {

      // }
      if (n == 1) {
        this.activeName = "first";
        // this.Performances()
        // this.upWokPes()
      }
      if (n == 2) {
        this.activeName = "second";
        this.catDinJis();
        this.commissions();
      }
    },
  },
};
</script>

<style scoped>
.inputWidth {
  width: 200px;
  margin: 20px 15px;
}

.spanMarin {
  margin-right: 20px;
}

.inputMig {
  width: 150px;
}

.inputWite {
  width: 210px;
}

.formMargin {
  margin-top: 30px;
}

.diFlex {
  display: flex;
}

.el-button {
  padding: 20px 60px;
}

.buttonMargin {
  margin-left: auto;
}

.divAuto {
  display: flex;
  justify-content: center;
  margin-top: 6%;
}

.groupMargin {
  /* margin-left: 20% */
}

.divMargin {
  margin-bottom: 20px;
}
</style>
